/*
 * @Author       : shenqing
 * @desc         : 同步请求
 * @Date         : 2022-10-10 17:45:59
 * @LastEditTime : 2022-10-11 09:02:06
 * @LastEditors  : shenqing
 * @FilePath     : \questionnaire\src\services\synchttp.js
 */
import {
    isNullOrEntry,
    getCookie
} from '@/services/util'
// import router from '@/router/index'
import syncRequest from 'sync-request'
let syncAjax = function (config) {
    let noAuth = isNullOrEntry(config.noAuth) ? true : config.noAuth
    // 判断是否cookie存在
    let usertoken = getCookie('_yh_uia_token')
    if ((isNullOrEntry(usertoken) || usertoken === 'null') && noAuth) {
    // 路由返回登陆页面
        return false
    }
    var result = syncRequest(config.type, config.url, {
        headers: {
            token: getCookie('token')
        },
        qs: isNullOrEntry(config.params) ? null : config.params,
        json: isNullOrEntry(config.data) ? null : config.data
    }).body
    return result
}
export default syncAjax
